import { contextBridge, ipcRenderer } from 'electron';

contextBridge.exposeInMainWorld('windows', {
  minimize: () => ipcRenderer.send('windows:minimize'),
  maximize: () => ipcRenderer.send('windows:maximize'),
  unmaximize: () => ipcRenderer.send('windows:unmaximize'),
  onIsMaximize: (callback: any) => ipcRenderer.on('isMaximize', callback),
  close: () => ipcRenderer.send('windows:close'),
  createBrowserView: (arg: any) => ipcRenderer.send('create-browser-view', arg),
  closeBrowserView: () => ipcRenderer.send('close-browser-view'),
  onStopLoading: (callback: any) => ipcRenderer.on('stop-loading', callback),
  onUserInfo: (
    callback: (
      _event: any,
      userInfo: {
        username: string;
        avator: string;
        userId: string;
      }
    ) => void
  ) => ipcRenderer.once('userInfo', callback),
});

contextBridge.exposeInMainWorld('store', {
  setValue: (key: string, value: any) =>
    ipcRenderer.send('store:setValue', key, value),
  getValue: (key: string) => ipcRenderer.sendSync('store:getValue', key),
  // 清楚所有缓存，慎用，不包含account，account需要自己清除，用于判断记录账号的缓存
  clear: () => ipcRenderer.send('store:clear'),
});
